package com.googlecode.garbagecan.springsecuritystudy.jaas;

import java.security.Principal;
import java.util.HashSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.providers.jaas.AuthorityGranter;


public class OSAuthorityGranterImpl implements AuthorityGranter {
	
	private static final Logger logger = LoggerFactory.getLogger(OSAuthorityGranterImpl.class);
	
	public Set grant(Principal principal) {
		logger.info("principal: " + principal);
		
		Set set = new HashSet();
		if (principal.getName().equals("root")) {
			set.add("ROLE_ADMIN");
			set.add("ROLE_USER");
		} else if (principal.getName().equals("fkong")) {
			set.add("ROLE_USER");
		}
		return set;
	}
}
